import axios from 'axios'
import Assert from '../common/Assert.js'

export const LogJobService = class LogJobService {
    static logJobService = null
    requestUrl = 'http://localhost/logJobs'

    static getInstance() {
        if (this.logJobService == null) {
            this.logJobService = new LogJobService()
        }
        return this.logJobService
    }

    /**
     * 分页查询
     * @param params
     */
    getByPage(params) {
        return axios.get(`${this.requestUrl}/page`,{
            params
        })
    }

    /**
     * 检查的方法
     * @param logJob
     * @param status
     */
    check(logJob, status) {
        if (!Assert.isNotNull(logJob.logtypeId, '请选择日志类型')) {
            return false
        }
        if (status) {
            if(logJob.parent != 1004 && parent != 1003){
                if (!Assert.isNotNull(logJob.caseLawId, '请选择案件')) {
                    return false
                }
            }
        }
        if(logJob.parent != 1004){
            if (!Assert.isNotNull(logJob.clientId, '请选择客户')) {
                return false
            }
        }
        if (!Assert.isNotNull(logJob.joblogStarttime, '请选择时间区间')) {
            return false
        }
        return true
    }

    /**
     * 保存的方法
     * @param logJob
     */
    save(logJob) {
        return axios.post(this.requestUrl, logJob)
    }

    /**
     * 删除的方法
     * @param id
     */
    remove(id){
        return axios.delete(`${this.requestUrl}/${id}`)
    }

    /**
     * 修改
     * @param logJob
     */
    update(logJob){
        return axios.put(this.requestUrl,logJob)
    }

    /**
     * 根据id查询
     * @param id
     */
    getById(id){
        return axios.get(`${this.requestUrl}/${id}`)
    }
}
